/**
 * 
 */
package wineshop.dao.Impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import wineshop.dao.ManagerDao;
import wineshop.domain.Manager;
import wineshop.utils.DBUtils;


/**
 * @author Administrator
 *
 */
public class ManagerDaoJDBCImpl implements ManagerDao {
	
	private static final String SQL_GET_BYID="select * from manager where login_id=?";

	/* (non-Javadoc)
	 * @see edu.fzu.bookshop.dao.ManagerDao#getManagerById(java.lang.String)
	 */
	public Manager getManagerById(String loginId) {
		
		Connection conn=DBUtils.getInstance().getConn();
		PreparedStatement pstmt=null;
		ResultSet rset=null;
		Manager manager=null;
		
		try {
			
			pstmt=conn.prepareStatement(SQL_GET_BYID);
			pstmt.setString(1, loginId);
			rset=pstmt.executeQuery();
			
			if(rset.next()){
			   manager=new Manager();
			   manager.setLoginId(rset.getString("login_id"));
			   manager.setLoginPwd(rset.getString("login_pwd"));
			   manager.setRealName(rset.getString("realname"));
			   manager.setStatus(rset.getString("status"));
			}
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			DBUtils.getInstance().releaseRes(conn, pstmt, rset);
		}
		
		return manager;
	}

}
